import subprocess
import sys
import os

class ShellCommandNode:
    def __init__(self):
        pass
    
    @classmethod
    def INPUT_TYPES(cls):
        return {
            "required": {
                "command": ("STRING", {
                    "multiline": True,
                    "default": "echo Hello World"
                }),
            },
        }

    RETURN_TYPES = ("STRING",)
    FUNCTION = "execute_command"
    CATEGORY = "utils"

    def execute_command(self, command):
        try:
            # 执行shell命令
            result = subprocess.run(
                command,
                shell=True,
                capture_output=True,
                text=True
            )
            
            # 获取输出
            output = result.stdout
            if result.stderr:
                output += "\nError:\n" + result.stderr
                
            return (output,)
            
        except Exception as e:
            return (f"Error executing command: {str(e)}",) 
